package cn.xorange.commons.file.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author : yangjian
 * @date : 2022/5/9
 */
@Configuration
public class ResourcesConfig implements WebMvcConfigurer {

    @Resource
    FileConfig fileConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /** 本地文件上传路径 */
        String localBucketName = fileConfig.localProperties().getBucketName();
        String localPath = fileConfig.localProperties().getLocalPath();
        registry.addResourceHandler("/"+ localBucketName + "/**")
                .addResourceLocations("file:///" + localPath + "/");

        String qiNiuBucketName = fileConfig.qiniuProperties().getBucketName();
        String qiNiuPath = fileConfig.qiniuProperties().getDomain();
        registry.addResourceHandler("/"+ qiNiuBucketName + "/**")
                .addResourceLocations(qiNiuPath + "/");
    }
}
